//
//  XVButton.m
//  整合
//
//  Created by  刘尚威 on 2017/3/3.
//  Copyright © 2017年  刘尚威. All rights reserved.
//

#import "XVButton.h"

@implementation XVButton

+ (UIButton *)ButtonWithTitle:(NSString *)title
                         font:(CGFloat)font
                    textColor:(UIColor *)textColor
              backgroundColor:(UIColor *)backgroundColor
              imageNameNormal:(NSString *)imageNameNormal
                    addToView:(UIView *)view
                        frame:(CGRect)frame
{
    UIButton *button = [[UIButton alloc] initWithFrame:frame];
    
    //按钮内容的垂直和水平位置
    button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    
    /*字符串不能为空，不然某些特定的判断会出错*/
    //按钮显示字符串
    if (title == nil) {
        [button setTitle:@"" forState:UIControlStateNormal];
    }
    else {
        [button setTitle:title forState:UIControlStateNormal];
    }
    
    //字符串大小
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    
    //字符串颜色
    if (textColor == nil)
    {
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    else
    {
        [button setTitleColor:textColor forState:UIControlStateNormal];
    }
    
    //按钮背景颜色
    if (backgroundColor == nil) {
        button.backgroundColor = [UIColor clearColor];
    }
    else {
        button.backgroundColor = backgroundColor;
    }
    
    if (view != nil) {
        [view addSubview:button];
    }
    
    
    return button;

}

@end
